var type=3;
$(function () {

	$(".hidden_menu").click(function(){
		$(".data_show").toggleClass('data_hidden');
		$(".ditu_box").toggleClass('ditu_position');
	});

/*	标导航栏样式*/
	$(".navTitle li").click(function(){
		$(".navTitle li").css("background","transparent");
		$(this).css("background","#2f94ff");
		// console.log($(this).text());
		var p = $(this).text();
		$(".filter_first .position").html("当前位置 : <span>"+p+"</span>");
	});
/*参数选项*/
	$(".main_filter .flag_tag").click(function(){
		$("#shuizhi_filter").addClass('shuizhi_hidden');
		// console.log($(".shuizhi_hidden").className());
		$(".main_filter .flag_tag").css({
			'backgroundImage':'linear-gradient(315deg, #ead11e, #ffa319)',
			'border':'3px solid #ffffff',
			'background':'#ffa319\0'
		});
		$(this).css({
			'backgroundImage':'linear-gradient(315deg, #ff7600, #ea462b)',
			'border':'5px solid #ffffff',
			'background':'#ff7600\0'
		});

		var canshu1 = $("#canshu1").is(":checked") ? 1 : 0;
		var canshu2 = $("#canshu2").is(":checked") ? 1 : 0;
		var canshu3 = $("#canshu3").is(":checked") ? 1 : 0;

		var canshu = canshu1 + "|" + canshu2 + "|" + canshu3;

		//console.log($(this).hasClass('shuizhi'));
		if($(this).hasClass('shuizhi')){
			$("#shuizhi_filter").removeClass('shuizhi_hidden');
				$(".shuizhi_filter .fl").css({
					"color":"#333333",
					"background":"transparent",
					"boxShadow":"none"
				});
				$("#shuizhiall").css({
					"background":"#2f94ff",
					"color":"#ffffff",
					"boxShadow":"0 0 2px #9ce1f9"
				});
				type = 3;
				jiancedianDetail(jiancedianid, type, canshu);
		}
		else if ($(this).hasClass('shuiliang')) {
		    type = 1;
		    jiancedianDetail(jiancedianid, type, canshu);
		}
		else
		{
		    type = 2;
		    jiancedianDetail(jiancedianid, type, canshu);
		}
	});
/*水质参数选项*/
	$(".shuizhi_filter .fl").click(function(){
		$(".shuizhi_filter .fl").css({
			"color":"#333333",
			"background":"transparent",
			"boxShadow":"none"
		});
		$(this).css({
			"background":"#2f94ff",
			"color":"#ffffff",
			"boxShadow":"0 0 2px #9ce1f9"
		});

		var canshu1 = $("#canshu1").is(":checked") ? 1 : 0;
		var canshu2 = $("#canshu2").is(":checked") ? 1 : 0;
		var canshu3 = $("#canshu3").is(":checked") ? 1 : 0;

		var canshu = canshu1 + "|" + canshu2 + "|" + canshu3;

		if($(this).hasClass('all'))
		{
		    type = 3;
		    jiancedianDetail(jiancedianid, type, canshu);
		}
		else if($(this).hasClass('zhuodu'))
		{
		    type = 4;
		    jiancedianDetail(jiancedianid, type, canshu);
		}
		else if ($(this).hasClass('yulv'))
		{
		    type = 5;
		    jiancedianDetail(jiancedianid, type, canshu);
		}
		else if ($(this).hasClass('andan')) {
		    type = 6;
		    jiancedianDetail(jiancedianid, type, canshu);
		}
		else if ($(this).hasClass('PH')) {
		    type = 7;
		    jiancedianDetail(jiancedianid, type, canshu);
		}
		else if ($(this).hasClass('COD')) {
		    type = 8;
		    jiancedianDetail(jiancedianid, type, canshu);
		}
		else if ($(this).hasClass('rjy')) {
		    type = 9;
		    jiancedianDetail(jiancedianid, type, canshu);
		}
	});

	$(".ditu_flag .mylocate").click(function(){
	    $(this).toggleClass('mylocate01');


	    if ($(this).hasClass('mylocate01'))
	    {
	        //plyyx.enableMassClear();
	        //map.removeOverlay(plyyx);

	        //for (var x in plyyxxz) {
	        //    plyyxxz[x].enableMassClear();
	        //    map.removeOverlay(plyyxxz[x]);
	        //}

	        
	    }
	    else
	    {
	        restore();
	        //map.clearOverlays();        //清除地图覆盖物

	        //plyyx.disableMassClear();
	        //map.addOverlay(plyyx);

	        //for (var x in plyyxxz) {
	        //    plyyxxz[x].disableMassClear();
	        //    map.addOverlay(plyyxxz[x]);
	        //}

	        //guanxian();

	        //var canshu1 = $("#canshu1").is(":checked") ? 1 : 0;
	        //var canshu2 = $("#canshu2").is(":checked") ? 1 : 0;
	        //var canshu3 = $("#canshu3").is(":checked") ? 1 : 0;

	        //var canshu = canshu1 + "|" + canshu2 + "|" + canshu3;

	        //jiancedian($("#quyu1").val(), canshu);
	        //if ($("#isshowfm").val() == "1") {
	        //    famen();
	        //}
	        
	    }
	    


	    //var point = new BMap.Point(119.805735, 31.3733); //定义一个中心点坐标
	    //map.centerAndZoom(point, 12); //设定地图的中心点和坐标并将地图显示在地图容器中
	});
	var timer1;
	$(".ditu_warn .warntic").click(function () {
	    $(this).toggleClass('warntic1');
	    $(".warn").toggle();

	    
	    //audio5js.play();
	    //var oAudio = document.getElementById('myaudio');
	    //if (oAudio.paused) {
	    //    oAudio.play();
	    //}
	    //else {
	    //    oAudio.pause();
	    //}
	});

	$(".ditu_warn .fenji").click(function () {
	    //$(this).toggleClass('bao1');
	    //$(".warn").toggle();
	    window.open("shuxing.html");

	    //audio5js.play();
	    //var oAudio = document.getElementById('myaudio');
	    //if (oAudio.paused) {
	    //    oAudio.play();
	    //}
	    //else {
	    //    oAudio.pause();
	    //}
	});
    //爆管图标点击
	$(".ditu_warn .bao").click(function () {
	    window.clearInterval(timer1);
	    if ($(this).hasClass("bao1")) {
	        for (var index in polylinespart)
	        {
	            map.removeOverlay(polylinespart[index]);
	        }
	        for (var index in famentemps) {
	            map.removeOverlay(famentemps[index]);
	        }
	        polylineper.disableMassClear();
	        polylineper.setStrokeWeight(3);
	        map.addOverlay(polylineper);
	        //2
	        polylineper2.disableMassClear();
	        polylineper2.setStrokeWeight(3);
	        map.addOverlay(polylineper2);
            //结束爆管，重新加载页面
	        location.reload();
	    }
	    else
	    {
	        map.removeOverlay(polylineper);
	        map.removeOverlay(polylineper2);
	        for (var index in polylinespart)
	        {
	            var polylinepart = polylinespart[index];
	            polylinepart.disableMassClear();
	            polylineper.setStrokeWeight(6);
	            map.addOverlay(polylinepart);
	        }


	    }
	    $(this).toggleClass('bao1');
	    //$(".warn").toggle();
	});

	$(".ditu_warn .chong").click(function () {
	    changeGuanXian3();
	    $(this).toggleClass('bao1');
	    //$(".warn").toggle();
	});


	$(".ditu_flag .routesave").click(function(){
	    
	    if ($("#guanxian").attr("disabled")) {

	        $(".fade").show();
	        $(".succ-pop").show();
	        
	    } else {
	        $("#guanxian").attr("disabled", "disabled");
	        var arr = new Array();
	        //console.log(polylinesUpdate);
	        for (var idd in polylinesUpdate)
	        {
	            arr.push({ "id": idd, "polyline": polylinesUpdate[idd] });//object类型
	            
	        }
	        polylinesEnd = { "polylines": arr };
	        //polylinesUpdate.
	        $.post("tools/getupload.ashx", {
	            "id": "saveguanxian",
	            "polylines": JSON.stringify(polylinesEnd)
	        }, function (data) {
	            polylinesEnd = {};
	            map.clearOverlays();        //清除地图覆盖物
	            guanxian();

	            var canshu1 = $("#canshu1").is(":checked") ? 1 : 0;
	            var canshu2 = $("#canshu2").is(":checked") ? 1 : 0;
	            var canshu3 = $("#canshu3").is(":checked") ? 1 : 0;

	            var canshu = canshu1 + "|" + canshu2 + "|" + canshu3;

	            jiancedian($("#quyu1").val(), canshu);
	            if ($("#isshowfm").val() == "1") {
	                famen();
	            }
	        });
	    }

	    //if ($("#quyu1").attr("disabled")) {
	    //    $("#quyu1").removeAttr("disabled");
	    //} else {
	    //    $("#quyu1").attr("disabled", "disabled");
	    //}

	    //if ($("#canshu").attr("disabled")) {
	    //    $("#canshu").removeAttr("disabled");
	    //} else {
	    //    $("#canshu").attr("disabled", "disabled");
	    //}

	    //if ($("#isshowfm").attr("disabled")) {
	    //    $("#isshowfm").removeAttr("disabled");
	        
	    //} else {
	    //    $("#isshowfm").attr("disabled", "disabled");
	    //}

	});
});

function updateresult() {


    $.ajax({
        //type: "post",
        url: "tools/getupload.ashx",
        dataType: "text",
        data: { id: "password", "password": $("#pw").val() },
        async: false,
        //timeout: 20000,
        success: function (data) {
            
            if (data == "success")
            {
                $(".ditu_flag .routesave").toggleClass('routesave01');
                $(".fade").hide();
                $(".succ-pop").hide();
                $("#pw").val("");

                $("#guanxian").removeAttr("disabled");
                map.clearOverlays();        //清除地图覆盖物

                var canshu1 = $("#canshu1").is(":checked") ? 1 : 0;
                var canshu2 = $("#canshu2").is(":checked") ? 1 : 0;
                var canshu3 = $("#canshu3").is(":checked") ? 1 : 0;

                var canshu = canshu1 + "|" + canshu2 + "|" + canshu3;

                jiancedian($("#quyu1").val(), canshu);
                if ($("#isshowfm").val() == "1") {
                    famen();
                }

                polylines = [];
                //var guanxianid = document.getElementById("guanxian21").value;
                $.post("tools/getupload.ashx", {
                    "id": "guanxian",
                    "type": "0"
                }, function (data) {
                    var testJson = $.parseJSON(data);
                    var renlist = testJson["regions"];
                    for (var i = 0; i < eval(renlist).length; i++) {
                        var ren = renlist[i];
                        var id = ren["id"].toString();
                        var name = ren["name"].toString();
                        var cailiao = ren["cailiao"].toString();
                        var chu = ren["chu"].toString();
                        var toumingdu = ren["toumingdu"].toString();
                        var color = ren["color"].toString();
                        var dian = ren["dian"].toString();
                        var dianlist = dian.split("|");
                        var points = [];
                        for (var j = 0; j < dianlist.length; j++) {
                            var p1 = dianlist[j].split(",")[0];
                            var p2 = dianlist[j].split(",")[1];
                            points.push(new BMap.Point(p1, p2));
                        }
                        //var polyline = new BMap.Polyline(points, {
                        //    strokeStyle: 'soild',
                        //    strokeWeight: chu,
                        //    strokeColor: color,
                        //    strokeOpacity: toumingdu
                        //});
                        //map.addOverlay(polyline);

                        //polylines[id] = polyline;//设置和修改值都可以使用该方法进行设定

                        //var sy = new BMap.Symbol(BMap_Symbol_SHAPE_BACKWARD_OPEN_ARROW, {
                        //    scale: 0.5,//图标缩放大小
                        //    strokeColor: '#fff',//设置矢量图标的线填充颜色
                        //    strokeWeight: '2',//设置线宽
                        //});
                        //var icons = new BMap.IconSequence(sy, '5%', '15%');

                        var polyline = new BMap.Polyline(points, {
                            enableEditing: false,//是否启用线编辑，默认为false
                            enableClicking: true,//是否响应点击事件，默认为true
                            //icons: [icons],
                            strokeWeight: '6',//折线的宽度，以像素为单位
                            strokeOpacity: 0.8,//折线的透明度，取值范围0 - 1
                            strokeColor: color //折线颜色
                        });

                        map.addOverlay(polyline);

                        polylines[id] = polyline;//设置和修改值都可以使用该方法进行设定

                        (function () {
                            var _name = name;
                            var _polyline = polyline;


                            _polyline.addEventListener("click", function () {
                                alert(_name)
                            });
                        })();

                    }

                    for (var idr in polylines) {
                        //alert(id);
                        polylines[idr].disableEditing();
                        if (idr == $("#guanxian").val()) {
                            //alert(id);
                            polylines[idr].enableEditing();

                            var index = idr;
                            var _polyline = polylines[idr];
                            _polyline.addEventListener("lineupdate", function () {
                                var areastr = "";
                                for (var arealength = 0; arealength < (_polyline.getPath().length) ; arealength++) {
                                    if (arealength != 0) {
                                        areastr += "|";
                                    }
                                    areastr += _polyline.getPath()[arealength].lng + "," + _polyline.getPath()[arealength].lat;
                                }
                                //alert(areastr);
                                //var jsonStr = { "id": id, "polyline": areastr };//object类型
                                polylinesUpdate[index] = areastr;
                                //console.log(polylinesUpdate);
                            });

                        }
                    }
                });
            }
            else
            {
                alert("密码错误");
            }
        }
    });
}
/*监听窗口的高度*/
// $(window).resize(function() {  
// 	var height = $(this).height();
// 	console.log(height);
// 	$(".ditu_box").css("height",height);   
// });
